from flask import Blueprint, jsonify,send_from_directory
import os
swagger_bp = Blueprint('swagger', __name__)


@swagger_bp.route('/')
def serve_knife4j():
    # 使用绝对路径
    static_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../static'))
    return send_from_directory(static_dir, 'doc.html')


@swagger_bp.route('/<path:filename>')
def serve_static(filename):
    static_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../static'))
    return send_from_directory(static_dir, filename)


# 提供 Swagger 配置
@swagger_bp.route('/v3/api-docs/swagger-config')
def swagger_config():
    config = {
        "configUrl": "/v3/api-docs/swagger-config",
        "urls": [
            {
                "name": "My API",
                "url": "/apispec_1.json"  # 指向你的 Swagger JSON 文件
            }
        ]
    }
    return jsonify(config)